package csci6450.chickenFriedFS.nuggetClient.threads;

// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
import csci6450.chickenFriedFS.nuggetClient.RuntimeSettings;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

// #[regen=yes,id=DCE.597A7A9A-3D02-E82C-61D6-1232ADE5350A]
// </editor-fold> 
public abstract class MetaServerCommunicator {

    private ObjectOutputStream outputStream = null;
    private ObjectInputStream inputStream = null;
    private Socket socket = null;

    public void initializeConnection() throws UnknownHostException, IOException {
        // open a socket connection
        socket = new Socket(RuntimeSettings.getInstance().getMetaServerIP(), RuntimeSettings.getInstance().getMetaServerPort());
        // open I/O streams for objects
        outputStream = new ObjectOutputStream(socket.getOutputStream());
        inputStream = new ObjectInputStream(socket.getInputStream());
    }

    public void closeConnection() throws IOException {
        this.socket.close();
    }

    public ObjectOutputStream getOutputStream(){
        return this.outputStream;
    }

    public ObjectInputStream getInputStream(){
        return this.inputStream;
    }

    public Socket getSocket(){
        return this.socket;
    }

}

